package com.gss.security.web;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;

import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.encoding.PasswordEncoder;
import org.springframework.security.authentication.encoding.ShaPasswordEncoder;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.gss.armory.domain.DocGeneralDetailsDTO;
import com.gss.armory.domain.DocGeneralDetailsDTO.DocumentFlowStatus;
import com.gss.armory.domain.DocumentWorkflowDetailsDTO;
import com.gss.armory.master.ApplicationUrlMappingDTO;
import com.gss.armory.service.AdminService;
import com.gss.armory.util.BootUpLoader;
import com.gss.common.service.MailService;
import com.gss.common.util.ApplicationConstants;
import com.gss.common.util.ApplicationMaps;
import com.gss.security.domain.RoleDetailsDTO;
import com.gss.security.domain.UserDetailsDTO;
import com.gss.security.persistence.AuthenticationDAO;
import com.gss.security.service.AuthenticationService;

@Controller
public class AuthenticationController {

	private Logger logger = Logger.getLogger(AuthenticationController.class);

	@Autowired
	private AuthenticationService authenticationService;

	@Autowired
	private AuthenticationDAO authenticationDAO;

	@Autowired
	private AdminService adminService;
	
	@Autowired
	MailService mailService;

	@RequestMapping("/sessionExpired.htm")
	public ModelAndView getSessionExpiredPage() {

		ModelAndView modelAndView = new ModelAndView("sessionExpired");
		Properties properties = new Properties();
		String url = null;
		try{
			properties.load(AuthenticationController.class.getResourceAsStream("/armory.properties"));
			url = properties.getProperty("logoutUrl");
		}
		catch(Exception e){
			logger.error(e.getMessage(),e);
		}
		
		if(null != url){
			modelAndView.addObject("redirectUrl", url);
		}
		
		return modelAndView;
	}

	@RequestMapping("/authenticate.htm")
	public ModelAndView authenticateUser() {
		logger.debug("inside authentication controller: method(authenticateUser)");

		
		UserDetailsDTO requestDTO = null;
		
		if(SecurityContextHolder.getContext().getAuthentication().getPrincipal() instanceof UserDetails){
			requestDTO = (UserDetailsDTO) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); 
		}
		else{
			return new ModelAndView("sessionClose");
		}
		 
		ModelAndView modelAndView = new ModelAndView();
		
		Collection<GrantedAuthority> additionalAuthorities = (Collection<GrantedAuthority>) requestDTO
				.getAuthorities();

		List<String> list = new ArrayList<String>();
		String enableForgetPasswordButton = null;
		Properties properties = new Properties();
		String url = null;
		
		if (!(SecurityContextHolder.getContext().getAuthentication().getPrincipal() instanceof UserDetailsDTO)) {
			
			try {
				properties.load(AuthenticationController.class.getResourceAsStream("/armory.properties"));
				enableForgetPasswordButton = properties.getProperty("enableForgetPassword");
				url = properties.getProperty("logoutUrl");
			} catch (IOException e) {
				logger.debug(e.getMessage(), e);
			}
			
			if(null != enableForgetPasswordButton){
				if(ApplicationConstants.ENABLE_FUNCTION.equalsIgnoreCase(enableForgetPasswordButton)){
					modelAndView.addObject("enableForgetPassword", enableForgetPasswordButton);
				}
				else{
					modelAndView.addObject("enableForgetPassword", ApplicationConstants.DISABLE_FUNCTION);
				}
			}
			
			if(null != url){
				modelAndView.addObject("redirectUrl", url);
			}
			modelAndView.setViewName("loginPage");
			return modelAndView;
		}
		
		for (GrantedAuthority authority : additionalAuthorities) {
			list.add(authority.getAuthority());
		}

		
		try {
			properties.load(AuthenticationController.class.getResourceAsStream("/armory.properties"));
			url = properties.getProperty("logoutUrl");
		} catch (IOException e) {
			logger.debug(e.getMessage(), e);
		}
		
		if(null != url){
			modelAndView.addObject("redirectUrl", url);
		}
		
		
		if (list.size() == 1) {
			modelAndView.addObject("list", list);
			modelAndView.addObject("size", list.size());
			modelAndView.setViewName("myapp.homepage");
		} else {
			modelAndView.addObject("list", list);
			modelAndView.addObject("size", list.size());
			modelAndView.setViewName("myapp.homepage");
		}
		
		return modelAndView;
	}

	@RequestMapping("/appropriateUser/{selectedRole}.htm")
	public ModelAndView selectAppropriateRole(
			@PathVariable(value = "selectedRole") String selectedRole) {
		/* logger.debug("ENTERED" + selectedRole); */

		ModelAndView modelAndView = new ModelAndView();
		String enableChangePasswordButton = null;
		Properties properties = new Properties();
		
		try {
			properties.load(AuthenticationController.class.getResourceAsStream("/armory.properties"));
			enableChangePasswordButton = properties.getProperty("enableChangePassword");
		} catch (IOException e) {
			logger.debug(e.getMessage(), e);
		}
		
		if(null != enableChangePasswordButton){
			if(ApplicationConstants.ENABLE_FUNCTION.equalsIgnoreCase(enableChangePasswordButton)){
				modelAndView.addObject("enableChangePassword", enableChangePasswordButton);
			}
			else{
				modelAndView.addObject("enableChangePassword", ApplicationConstants.DISABLE_FUNCTION);
			}
		}
		
		if (selectedRole.equals(ApplicationConstants.ADMIN_ROLE)) {
			modelAndView.addObject("armoryMasterData",
					ApplicationMaps.ARMORY_MASTER_DATA);
			modelAndView.setViewName("welcome");
		} else {
			modelAndView.setViewName("welcome");
		}

		return modelAndView;
	}

	@RequestMapping("/login.htm")
	public ModelAndView getLoginPage() {
		logger.debug("inside getLoginPage method ....");
		ModelAndView modelAndView = new ModelAndView("loginPage");
		String enableForgetPasswordButton = null;
		Properties properties = new Properties();
		String url = null;
		
		try {
			properties.load(AuthenticationController.class.getResourceAsStream("/armory.properties"));
			enableForgetPasswordButton = properties.getProperty("enableForgetPassword");
			url = properties.getProperty("logoutUrl");
		} catch (IOException e) {
			logger.debug(e.getMessage(), e);
		}
		
		if(null != enableForgetPasswordButton){
			if(ApplicationConstants.ENABLE_FUNCTION.equalsIgnoreCase(enableForgetPasswordButton)){
				modelAndView.addObject("enableForgetPassword", enableForgetPasswordButton);
			}
			else{
				modelAndView.addObject("enableForgetPassword", ApplicationConstants.DISABLE_FUNCTION);
			}
		}
		
		if(null != url){
			modelAndView.addObject("redirectUrl", url);
		}

		return modelAndView;
	}

	@RequestMapping(value="/changePwdDialog.htm")
	public void changePasswordUsingDialog(@RequestParam(value = "password") String password, HttpServletResponse response){
		UserDetailsDTO userdetailsDTO = (UserDetailsDTO) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		logger.debug("inside authentication controller: method(changePasswordUsingDialog): updating password for: " + userdetailsDTO.getUsername() +
				"  :: New Password is: " + password);
		try {
			if (null != userdetailsDTO) {
				if (authenticationService.checkpassword(password)) {
					userdetailsDTO.setUpdatedDate(new Date());
					
					PasswordEncoder encoder = new ShaPasswordEncoder(256);
					String encPassword = encoder.encodePassword(password, null);
					
					userdetailsDTO.setPassword(encPassword);
					authenticationService.updateUserPassword(userdetailsDTO);
					response.getWriter().print("Password Changed Successfully.");
				} 
				else {
					response.getWriter().print("Entered password doesn't meet the required criteria. Please enter correct password.");
					
				}
			}
		} catch (IOException e) {
			logger.error(e.getMessage(),e);
		}
	}
	
	@RequestMapping(value = "/changePassword.htm")
	public ModelAndView changePasswordForCurrentUser(@RequestParam(value = "password") String password, HttpServletResponse response) {

		UserDetailsDTO userdetailsDTO = (UserDetailsDTO) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		logger.debug("inside authentication controller: method(changePasswordForCurrentUser): updating password for: " + userdetailsDTO.getUsername() +
				"  :: New Password is: " + password);
		ModelAndView modelAndView = new ModelAndView();
		try {
			if (null != userdetailsDTO) {
				if (authenticationService.checkpassword(password)) {
					userdetailsDTO.setUpdatedDate(new Date());
					
					PasswordEncoder encoder = new ShaPasswordEncoder(256);
					String encPassword = encoder.encodePassword(password, null);
					
					userdetailsDTO.setPassword(encPassword);
					authenticationService.updateUserPassword(userdetailsDTO);
					modelAndView.setViewName("loginPage");
					response.getWriter().print("Password Changed Successfully.");
				} 
				else {
					modelAndView.addObject("error", "Entered password doesn't meet the required criteria. Please enter correct password.");
					modelAndView.setViewName("changePassword");
				}
			}
		} catch (IOException e) {
			logger.error(e.getMessage(),e);
		}
		return modelAndView;
	}

	@RequestMapping(value = "/changepasswd.htm")
	public ModelAndView changePassword() {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("changePassword");
		return mav;
	}

	@RequestMapping("/updatePwd.htm")
	public ModelAndView updatePwd(
			@RequestParam("cnfpassword") String newpassword,
			HttpServletResponse servletResponse) throws IOException {

		ModelAndView modelAndView = new ModelAndView();

		UserDetailsDTO userdetailsDTO = (UserDetailsDTO) SecurityContextHolder
				.getContext().getAuthentication().getPrincipal();
		logger.debug("inside authentication controller: method(updatePwd): updating password for: " + userdetailsDTO.getUsername() +
				"  :: New Password is: " + newpassword);
		
		if (userdetailsDTO != null) {
			if (authenticationService.checkpassword(newpassword)) {
				userdetailsDTO.setUpdatedDate(new Date());
				
				PasswordEncoder encoder = new ShaPasswordEncoder(256);
				String encPassword = encoder.encodePassword(newpassword, null);
				
				userdetailsDTO.setPassword(encPassword);
				authenticationService.updateUserPassword(userdetailsDTO);
				modelAndView.setViewName("loginPage");
			} 
			else {
				modelAndView.addObject("error", "Entered password doesn't meet the required criteria. Please enter correct password.");
				modelAndView.setViewName("changePassword");
			}
		}
		return modelAndView;
	}

	@RequestMapping("/forgetPassword")
	public void forgetPassword(@RequestParam("userName") String userName,HttpServletResponse response) throws IOException
	{
		UserDetailsDTO userDetailsDTO = (UserDetailsDTO) authenticationService.loadUserByUsername(userName);
		if(userDetailsDTO!=null)
		{
			response.getWriter().write("Your Password Sent to Your E-Mail Id");
			
			Long newPassword = new Date().getTime();
			String mailBody = authenticationService.getMailForgetPassword(userDetailsDTO, newPassword);
			String mailSubject = "DMS Forget Password";
			
			String toEMailId = userDetailsDTO.getEmailId();
			Set<String> emailSet = new HashSet<String>();
			emailSet.add(toEMailId);
			String []toEmailArray = emailSet.toArray(new String[0]);
			boolean resultOfMailSending = mailService.sendMailNotification(toEmailArray, null, mailBody, mailSubject);
			
			if(resultOfMailSending){
				PasswordEncoder encoder = new ShaPasswordEncoder(256);
				String encPassword = encoder.encodePassword(newPassword.toString(), null);
				userDetailsDTO.setPassword(encPassword.toString());
				authenticationService.updateUserPassword(userDetailsDTO);
			}
			else{
				response.getWriter().write("Unable to send mail on Email Id of user");
			}
		}
		else{
			response.getWriter().write("Invalid UserId");
		}
	}
	
	@RequestMapping("/selectRole.htm")
	public ModelAndView selectAppropriateRole() {
		ModelAndView modelAndView = new ModelAndView();

		UserDetailsDTO requestDTO = (UserDetailsDTO) SecurityContextHolder
				.getContext().getAuthentication().getPrincipal();
		Collection<GrantedAuthority> additionalAuthorities1 = (Collection<GrantedAuthority>) requestDTO
				.getAuthorities();

		List<String> list = new ArrayList<String>();

		for (GrantedAuthority authority : additionalAuthorities1) {
			list.add(ApplicationMaps.ROLEID_ROLENAME_MAP.get(authority
					.getAuthority()));
		}

		modelAndView.addObject("rolesList", list);

		modelAndView.setViewName("selectRole");

		return modelAndView;
	}

	@RequestMapping("/selectView.htm")
	public ModelAndView selectView() {
		UserDetailsDTO requestDTO = (UserDetailsDTO) SecurityContextHolder
				.getContext().getAuthentication().getPrincipal();
		Collection<GrantedAuthority> additionalAuthorities = (Collection<GrantedAuthority>) requestDTO
				.getAuthorities();

		Set<Integer> appIdSet = new HashSet<Integer>();
		HashMap<Integer, String> APP_ID_NAME_MAP = new HashMap<Integer, String>();
		Set<ApplicationUrlMappingDTO> applicationUrlMappingSet = new HashSet<ApplicationUrlMappingDTO>();
		
		ModelAndView modelAndView = new ModelAndView();

		String enableChangePasswordButton = null;
		Properties properties = new Properties();
		
		try {
			properties.load(AuthenticationController.class.getResourceAsStream("/armory.properties"));
			enableChangePasswordButton = properties.getProperty("enableChangePassword");
		} catch (IOException e) {
			logger.debug(e.getMessage(), e);
		}
		
		if(null != enableChangePasswordButton){
			if(ApplicationConstants.ENABLE_FUNCTION.equalsIgnoreCase(enableChangePasswordButton)){
				modelAndView.addObject("enableChangePassword", enableChangePasswordButton);
			}
			else{
				modelAndView.addObject("enableChangePassword", ApplicationConstants.DISABLE_FUNCTION);
			}
		}
		
		for (GrantedAuthority authority : additionalAuthorities) {
			RoleDetailsDTO roleDetailsDTO = (RoleDetailsDTO) authority;
			
			if (authority.getAuthority().equals(ApplicationConstants.ADMIN_ROLE)) {
				modelAndView.addObject("armoryMasterData",ApplicationMaps.ARMORY_MASTER_DATA);
				modelAndView.addObject("requestDTO", requestDTO);
				modelAndView.setViewName("welcomeContent");
			} else {
				modelAndView.setViewName("welcomeContent");
			}
			
//			logger.debug("role assigned to user in central database: " + roleDetailsDTO.getAppId());
//			if (!(roleDetailsDTO.getAppId().equals(ApplicationConstants.APP_ID))) {
//				appIdSet.add(roleDetailsDTO.getAppId());
//			}
		}
		
		for (Integer appId : appIdSet) {
			DetachedCriteria applicationCriteria = DetachedCriteria.forClass(ApplicationUrlMappingDTO.class);
			applicationCriteria.add(Restrictions.eq("appId", appId));
			applicationUrlMappingSet.addAll(authenticationService.loadUrlMappingList(applicationCriteria));	
		}
		for (ApplicationUrlMappingDTO applicationUrlMappingDTO : applicationUrlMappingSet) {
			APP_ID_NAME_MAP.put(applicationUrlMappingDTO.getAppId(), applicationUrlMappingDTO.getAppName());
		}
		logger.debug("Number of applications in which the user is mapped are: " + APP_ID_NAME_MAP.size() + " and the application ids for that are: " + APP_ID_NAME_MAP.keySet());
		modelAndView.addObject("appMap", APP_ID_NAME_MAP);
		return modelAndView;

	}

	@RequestMapping("/loadDashBoard")
	public ModelAndView loadDashBoard() {
		ModelAndView modelAndView = new ModelAndView("dashboard");
		UserDetailsDTO requestDTO = (UserDetailsDTO) SecurityContextHolder
				.getContext().getAuthentication().getPrincipal();
		List<DocGeneralDetailsDTO> docGeneralDetailsDTO = new ArrayList<DocGeneralDetailsDTO>();
		HashMap<Enum, HashMap<String, Integer>> dashboardData = new HashMap<Enum, HashMap<String, Integer>>();

		if (null != requestDTO) {
			List<DocumentWorkflowDetailsDTO> workflowDetailsDTO = adminService.getOpenDocsForUsers(requestDTO);

			for (DocumentWorkflowDetailsDTO documentWorkflowDetailsDTO : workflowDetailsDTO) {
				docGeneralDetailsDTO.addAll(adminService.getDocGeneralDetails(documentWorkflowDetailsDTO));
			}

			DocGeneralDetailsDTO detailsDTO;
			DocumentWorkflowDetailsDTO wfDetailsDTO;
			for (int i = 0; i < docGeneralDetailsDTO.size(); i++) {
				detailsDTO = docGeneralDetailsDTO.get(i);
				wfDetailsDTO = workflowDetailsDTO.get(i);

				switch (detailsDTO.getDocumentStatus()) {
				case Wfip:
					updateMap(dashboardData, wfDetailsDTO.getWfStatus(),
							detailsDTO.getDocType());
					break;
				case Due:
					updateMap(dashboardData, DocumentFlowStatus.Due,
							detailsDTO.getDocType());
					break;
				case Overdue:
					updateMap(dashboardData, DocumentFlowStatus.Overdue,
							detailsDTO.getDocType());
					break;
				case RenewWfip:
					populateMap(dashboardData, detailsDTO.getDocCode(),
							detailsDTO.getDocType(),
							detailsDTO.getDocumentStatus());

					break;
				default:
					break;
				}
			}
			String enableChangePasswordButton = null;
			Properties properties = new Properties();
			
			try {
				properties.load(AuthenticationController.class.getResourceAsStream("/armory.properties"));
				enableChangePasswordButton = properties.getProperty("enableChangePassword");
			} catch (IOException e) {
				logger.debug(e.getMessage(), e);
			}
			
			if(null != enableChangePasswordButton){
				if(ApplicationConstants.ENABLE_FUNCTION.equalsIgnoreCase(enableChangePasswordButton)){
					modelAndView.addObject("enableChangePassword", enableChangePasswordButton);
				}
				else{
					modelAndView.addObject("enableChangePassword", ApplicationConstants.DISABLE_FUNCTION);
				}
			}
			modelAndView.addObject("statusMap", ApplicationMaps.STATUS_NAME_MAP);
			modelAndView.addObject("dashboardData", dashboardData);
			modelAndView.addObject("sizeOfData", dashboardData.size());
		}
		return modelAndView;
	}

	private void populateMap(
			HashMap<Enum, HashMap<String, Integer>> dashboardData,
			String docCode, String type, DocumentFlowStatus documentFlowStatus) {
		long documentCode = Long.parseLong(docCode);
		DocGeneralDetailsDTO docGeneralDetailsDTO = adminService
				.getDocumentForDocCode(docCode).get(0);

		if (docGeneralDetailsDTO.getDocumentStatus().equals(
				DocumentFlowStatus.Due)) {
			if (!dashboardData.containsKey(documentFlowStatus)) {
				dashboardData.put(docGeneralDetailsDTO.getDocumentStatus(),
						new HashMap<String, Integer>());
			}
			if (!dashboardData.get(docGeneralDetailsDTO.getDocumentStatus())
					.containsKey(type)) {
				dashboardData.get(docGeneralDetailsDTO.getDocumentStatus())
						.put(type, 0);
			}
			dashboardData.get(docGeneralDetailsDTO.getDocumentStatus()).put(
					type,
					dashboardData.get(docGeneralDetailsDTO.getDocumentStatus())
							.get(type) + 1);
		} else if (docGeneralDetailsDTO.getDocumentStatus().equals(
				DocumentFlowStatus.Overdue)) {
			if (!dashboardData.containsKey(docGeneralDetailsDTO
					.getDocumentStatus())) {
				dashboardData.put(docGeneralDetailsDTO.getDocumentStatus(),
						new HashMap<String, Integer>());
			}
			if (!dashboardData.get(docGeneralDetailsDTO.getDocumentStatus())
					.containsKey(type)) {
				dashboardData.get(docGeneralDetailsDTO.getDocumentStatus())
						.put(type, 0);
			}
			dashboardData.get(docGeneralDetailsDTO.getDocumentStatus()).put(
					type,
					dashboardData.get(docGeneralDetailsDTO.getDocumentStatus())
							.get(type) + 1);
		}
	}
	
	/*private void populateMap(
			HashMap<Enum, HashMap<String, Integer>> dashboardData,
			long docId, String type, DocumentFlowStatus documentFlowStatus) {
//		long documentCode = Long.parseLong(docId);
		DocGeneralDetailsDTO docGeneralDetailsDTO = adminService
				.getDocumentForDocId(docId);

		if (docGeneralDetailsDTO.getDocumentStatus().equals(
				DocumentFlowStatus.RenewWfip)) {
			if (!dashboardData.containsKey(documentFlowStatus)) {
				dashboardData.put(docGeneralDetailsDTO.getDocumentStatus(),
						new HashMap<String, Integer>());
			}
			if (!dashboardData.get(docGeneralDetailsDTO.getDocumentStatus())
					.containsKey(type)) {
				dashboardData.get(docGeneralDetailsDTO.getDocumentStatus())
						.put(type, 0);
			}
			dashboardData.get(docGeneralDetailsDTO.getDocumentStatus()).put(
					type,
					dashboardData.get(docGeneralDetailsDTO.getDocumentStatus())
							.get(type) + 1);
		} else if (docGeneralDetailsDTO.getDocumentStatus().equals(
				DocumentFlowStatus.Overdue)) {
			if (!dashboardData.containsKey(docGeneralDetailsDTO
					.getDocumentStatus())) {
				dashboardData.put(docGeneralDetailsDTO.getDocumentStatus(),
						new HashMap<String, Integer>());
			}
			if (!dashboardData.get(docGeneralDetailsDTO.getDocumentStatus())
					.containsKey(type)) {
				dashboardData.get(docGeneralDetailsDTO.getDocumentStatus())
						.put(type, 0);
			}
			dashboardData.get(docGeneralDetailsDTO.getDocumentStatus()).put(
					type,
					dashboardData.get(docGeneralDetailsDTO.getDocumentStatus())
							.get(type) + 1);
		}
	}*/
	

	private void updateMap(
			HashMap<Enum, HashMap<String, Integer>> dashboardData, Enum status,
			String type) {

		if (!dashboardData.containsKey(status)) {
			dashboardData.put(status, new HashMap<String, Integer>());
		}

		if (!dashboardData.get(status).containsKey(type)) {
			dashboardData.get(status).put(type, 0);
		}

		dashboardData.get(status).put(type,
				dashboardData.get(status).get(type) + 1);

	}
	
	@RequestMapping(value="changeModule.htm")
	public ModelAndView changeModule(@RequestParam String appId){
		logger.debug("inside authentication controller: method(changeModule): User had requested to change to the module having id: " + appId);
		
		ModelAndView modelAndView = new ModelAndView();
		try{
			UserDetailsDTO userDetailsDTO =  (UserDetailsDTO) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
			
			DetachedCriteria applicationCriteria = DetachedCriteria.forClass(ApplicationUrlMappingDTO.class);
			applicationCriteria.add(Restrictions.eq("appId", Integer.parseInt(appId)));
			List<ApplicationUrlMappingDTO> applicationUrlMappingList = authenticationService.loadUrlMappingList(applicationCriteria);
			modelAndView.addObject("username", userDetailsDTO.getUsername());
			modelAndView.addObject("password", userDetailsDTO.getTxtPassword());
			modelAndView.addObject("urlToRedirect", applicationUrlMappingList.get(0).getAppUrl());
			logger.debug("The url on which " + userDetailsDTO.getUsername() + " is redirecting is: " + applicationUrlMappingList.get(0).getAppUrl());
		}
		catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
		modelAndView.setViewName("changeModule/changeModule");
		return modelAndView;
	}
	
	@RequestMapping(value="logoutPage.htm")
	public String getLogoutPage(){
		logger.debug("inside getLogoutPage: ");
		String viewname = "logoutPage";
		return viewname;
	}
	
}
